Skip to content

Conversation

@j-d-ha
Copy link
Collaborator

@j-d-ha j-d-ha commented Jan 16, 2026

🚀 Pull Request

📋 Summary

This PR adds support for configurable Guid format strings in DynamoMapper, allowing developers to control how Guid values are serialized to and from DynamoDB. The default format remains "D" (hyphenated format), but users can now specify alternative formats like "N" (no hyphens), "B" (braces), or "P" (parentheses) via the GuidFormat property on the [DynamoMapper] attribute.

Key Changes:

  • Added GuidFormat property to MapperOptions (internal) and DynamoMapperAttribute (public API)
  • Updated TypeMappingStrategyResolver to pass format string when mapping Guid types
  • Enhanced PropertyMappingCodeRenderer to correctly position the out var parameter after type-specific arguments
  • All Guid format strings ("N", "D", "B", "P") are now supported with proper documentation

✅ Checklist

  • My changes build cleanly
  • I've added/updated relevant tests
  • I've added/updated documentation or README
  • I've followed the coding style for this project
  • I've tested the changes locally (if applicable)

🧪 Related Issues or PRs

Part of Phase 1 implementation for property-level customization.


💬 Notes for Reviewers

The key technical challenge here was adjusting the parameter ordering in PropertyMappingCodeRenderer.cs (lines 98-104). Previously, the out var parameter was always inserted at position 1, but with type-specific arguments like format strings, it needs to be inserted after those arguments. The fix calculates the correct position dynamically based on FromTypeSpecificArgs.Length.

This change maintains backward compatibility since the default Guid format remains "D", matching the existing behavior.

Copy link
Contributor

@ncipollina ncipollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really want to be able to specify format on a per field basis.

/// </item>
/// </list>
/// </remarks>
public string GuidFormat { get; set; } = "D";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔄 I don't like these being separate fields. I would rather have a single Format string field. Depending on what the type is, that would determine where/how the format is applied.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be applying these on the DynamoFieldAttribute.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the overall format for all items. I am adding per-field formats next.

ncipollina
ncipollina previously approved these changes Jan 16, 2026
Copy link
Contributor

@ncipollina ncipollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ The requested change will be handled in a future PR.

- Added `GuidFormat` option to `MapperOptions` with a default format of "D".
- Updated `TypeMappingStrategyResolver` to respect the Guid format specified in `MapperOptions`.
- Enhanced `PropertyMappingCodeRenderer` to handle type-specific arguments, including the Guid format.
- Updated `DynamoMapperAttribute` to expose the `GuidFormat` option and document valid formats.
- Added instructions to mention related issues in the PR body.
- Clarified the use of `closes #<issue number>` for resolving issues.
- Updated the PR template to include related issues or PRs.
@j-d-ha j-d-ha force-pushed the feature/Add-Guid-Format-Override-Support branch from 9194756 to dc05483 Compare January 16, 2026 21:33
… setup

- Standardized syntax for dictionary and list initializations in tests.
- Added trailing commas for multi-line collections to improve diff readability.
- Replaced `Assert.Equal` with `Assert.Single` where applicable for clarity.
- Improved parameter naming in `GetGuid` method calls across tests.

refactor(Guid-handling): refine methods for Guid parsing with customizable format

- Removed redundant Guid parsing methods to avoid code duplication.
- Introduced default "D" format for `Guid` and nullable `Guid` parsing methods.
- Simplified method signatures to improve usability and consistency.
- Updated XML documentation to clarify `format` defaults and valid format strings.
…rameters

- Removed redundant `format:` named parameters in method calls across test snapshots.
- Updated property mappings to use positional arguments where applicable.
- Simplified type-specific argument handling by treating all arguments as positional in `PropertyMappingSpecBuilder`.
@j-d-ha j-d-ha merged commit fcc8cd8 into main Jan 16, 2026
1 check passed
@j-d-ha j-d-ha deleted the feature/Add-Guid-Format-Override-Support branch January 16, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants